Skip to content

Conversation

@migsan1104
Copy link

This PR addresses issue #780 by implementing behavior consistent with modern editors:

If the user right-clicks inside an existing selection, the selection is preserved.

If the user right-clicks outside the selection, the caret moves to the clicked position and the context menu is invoked at the new location. The selection is also cleared.

Added build/ to .gitignore to avoid tracking generated files.

…click outside selection the selection is cleared and caret is moved. Context menu is then opened based on new caret location.
…t when right-clicked outside selection and show context menu at new caret location.
@migsan1104
Copy link
Author

Thank you for letting me work on this project. :)

@migsan1104 migsan1104 closed this Jun 9, 2025
@migsan1104 migsan1104 reopened this Jun 9, 2025
@dail8859
Copy link
Owner

Hi @migsan1104 apologies for the delay.

Although I think this is likely a valid solution, all the code within the scintilla directory is directly from a 3rd party library so I wouldn't want to maintain a separate copy or need to remember to edit it every time.

My first guess is that this section of code is the best place to handle it:

connect(editor, &ScintillaNext::customContextMenuRequested, this, [=](const QPoint &pos) {
contextMenuPos = editor->positionFromPoint(pos.x(), pos.y());
QStringList actionNames = {
"Cut",
"Copy",
"Paste",
"Delete",
"",
"SelectAll",
"",
"Base64Encode",
"URLEncode",
"",
"Base64Decode",
"URLDecode"
};
// If the entry exists in the settings, use that
ApplicationSettings *settings = app->getSettings();
if (settings->contains("Gui/EditorContextMenu")) {
actionNames = settings->value("Gui/EditorContextMenu").toStringList();
}
// If the cursor is at a URL, prepend the action
URLFinder *urlFinder = editor->findChild<URLFinder *>(QString(), Qt::FindDirectChildrenOnly);
if (urlFinder && urlFinder->isEnabled() && urlFinder->isURL(contextMenuPos)) {
actionNames.prepend("");
actionNames.prepend("CopyURL");
}
auto menu = buildMenu(actionNames);
menu->addSeparator();
menu->addMenu(ui->menuMarkAllOccurrences);
menu->addMenu(ui->menuClearMarks);
menu->popup(QCursor::pos());
});

That is where the main window shows the context menu and may need to do some checking to see if its in a selection or not and possibly clear the selection.

Notepad++ also has this behavior and also uses Scintilla so it might have a recommended way of handling this case, but I havent taken the time to dig into the Notepad++ source code in quite a while.

@dail8859 dail8859 closed this Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants